package com.app.worldcupapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

public class MyAdapter extends BaseAdapter {

    List list;
    Context context;

    public MyAdapter(List list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_listview, parent, false);
        //获取MyBean.ListBean中position位置的数据，赋值给listbean
        MyBean.ListBean listBean = (MyBean.ListBean) list.get(position);

        //从项布局中获取控件，findViewById前面要加上(view.)。
        TextView textView = view.findViewById(R.id.tv_mingci);
        TextView textView1 = view.findViewById(R.id.tv_guojia);
        TextView textView2 = view.findViewById(R.id.tv_jifen);
        ImageView icon = view.findViewById(R.id.iv_qiudui);

        // 利用listBean中的数据，修改控件的属性完成数据呈现
        //设置文本控件所显示文字
        textView.setText(listBean.getOrder());
        textView1.setText(listBean.getNation());
        textView2.setText(listBean.getScore()+"");
        // 设置图片控件所显示的图片
        Picasso.with(context).load("http://10.1.65.38:8081/"+listBean.getFlag()).into(icon);

        return view;  // 返回填充了内容的项视图对象。

    }
}

